//
//  DigitalSelectTableViewCell.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/7/31.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "DigitalTableViewCell.h"
#import "DigitalTransferViewController.h"
#import "DigitalWithdrawViewController.h"
#import "DigitalExchangeViewController.h"
#import "DigitalDepositViewController.h"

@interface DigitalTableViewCell ()

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *actions;

@property (weak, nonatomic) IBOutlet UIButton *depositButton;
@property (weak, nonatomic) IBOutlet UIButton *exchangeButton;
@property (weak, nonatomic) IBOutlet UIButton *transferButton;
@property (weak, nonatomic) IBOutlet UIButton *withdrawButton;

@end

@implementation DigitalTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.depositButton setTitle:JFMainLocalizedString(@"deposit.deposit") forState:UIControlStateNormal];
    [self.exchangeButton setTitle:JFMainLocalizedString(@"exchange.exchange") forState:UIControlStateNormal];
    [self.transferButton setTitle:JFMainLocalizedString(@"withdraw.transfer") forState:UIControlStateNormal];
    [self.withdrawButton setTitle:JFMainLocalizedString(@"withdraw.withdraw") forState:UIControlStateNormal];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setEntity:(BalanceListEntity *)entity {
    _entity = entity;
    
    [self.image setImage:[UIImage imageNamed:entity.imageName]];
    self.name.text = [entity.asset_address stringByAppendingString:@"/"];
    self.name1.text = entity.assetDescribe;
//    self.vaule.text = entity.available_balance_display;
    self.usMoney.text = [NSString stringWithFormat:@"≈$ %@", MoneyFormat(entity.indicative_usd_equivalent)];
    if ([entity.asset_address isEqualToString:@"HKD"] || [entity.asset_address isEqualToString:@"USD"] || [entity.asset_address isEqualToString:@"SGD"]) {
        self.vaule.text = MoneyFormat(entity.available_balance_display);
    }else {
        self.vaule.text = entity.available_balance_display;
    }
    
    [self.actions enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj setTitleColor:UIColorFromHex(0xCCCCCC) forState:UIControlStateDisabled];
        obj.enabled = entity.actionType & (1 << idx);
    }];
}

- (IBAction)depositAction:(id)sender {
    if (self.action) {
        self.action(FunctionActionTypeDeposit);
    }
}

- (IBAction)exchangeAction:(id)sender {
    if (self.action) {
        self.action(FunctionActionTypeExchange);
    }
}

- (IBAction)transferAction:(id)sender {
    if (self.action) {
        self.action(FunctionActionTypeTransfer);
    }
}

- (IBAction)withdrawAction:(id)sender {
    if (self.action) {
        self.action(FunctionActionTypeWithdraw);
    }
}

@end
